Public Class CustomerDetailsReport
    Inherits [lib].BasePage

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DataGrid2 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents ContentPaneFooter1 As ccapps.BillingNetControlLibrary.ContentPaneFooter

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.PageTitle = "Customer Details Usage Report"

        If (Not Me.IsPostBack) Then
            listHistory(0)
        End If

        'Me.ContentPaneFooter1.NavigateBackClientFunction = String.Format("javascript:location.href='{0}'", IIf(Me.DataGrid1.Visible, "CDRViewer.aspx", "CDRViewerReport.aspx"))
    End Sub

    Private Sub listHistory(ByVal pageIndex As Integer)
        Try

            Me.DataGrid2.CurrentPageIndex = pageIndex
            Me.DataGrid2.DataSource = persistent.myDBConn.myORATable("select lu.username, cdvl.custcode, cdvl.viewdate from eu_bill.customer_details_view_log cdvl, billintra.login_user lu where lu.userid = cdvl.userid order by viewdate desc")
            Me.DataGrid2.DataBind()

        Catch ex As Exception
            Alert(ex.Message, Me)
        End Try

        Me.DataGrid2.Visible = Me.DataGrid2.Items.Count > 0
        Me.ContentPaneFooter1.ConfirmButton.Visible = Me.DataGrid2.Visible AndAlso Me.DataGrid2.Items.Count > 0

    End Sub

    Private Sub DataGrid2_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid2.PageIndexChanged
        Me.listHistory(e.NewPageIndex)
    End Sub







    Private Sub ContentPaneFooter1_Confirmed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContentPaneFooter1.Confirmed
        Dim dataGrid As DataGrid = Me.DataGrid2
        Dim currentPageIndex = dataGrid.CurrentPageIndex
        dataGrid.AllowPaging = False

        Me.listHistory(0)

        Dim stringWrite As New System.IO.StringWriter

        Dim htmlWrite As New HtmlTextWriter(stringWrite)

        dataGrid.RenderControl(htmlWrite)

        Me.setFiletoDownload("Requests.xls", stringWrite.ToString())

        dataGrid.AllowPaging = True

        Me.listHistory(currentPageIndex)

    End Sub


    Private Sub setFiletoDownload(ByVal fileName As String, ByVal fileContent As String)

        Response.Clear()
        Response.Buffer = True
        Response.AddHeader("content-disposition", "attachment;filename=" & fileName)

        Response.Cache.SetCacheability(HttpCacheability.NoCache)

        Response.ContentType = "application/vnd.ms-excel"

        Response.Charset = ""

        Me.EnableViewState = False

        Response.Write(fileContent)

        Response.End()

    End Sub

End Class
